<?php
class  Module_CallCenter_YunKeFu_Call
{
    private static $obj = [];
    private $model = null;

    private function __construct($line)
    {
        $this->model = new Lib_CallCenter_YunKeFu_Main($line);
    }

    public static function getInstance($line = 1)
    {
        if (!isset(self::$obj[$line])) {
            self::$obj[$line] = new self($line);
        }
        return self::$obj[$line];
    }
    //外呼
    public function callOut($data){
        $request_data['FromExten'] = empty($data['workerId']) ? '' : $data['workerId'];
        $request_data['Exten'] = empty($data['toTel']) ? '' : $data['toTel'];
        $request_data['OutShow'] = empty($data['OutShow']) ? '' : $data['OutShow'];
        $request_data['ActionID'] = empty($data['ActionID']) ? '' : $data['ActionID'];
        if(!Lib_Notice::checkData($request_data,['FromExten','Exten'])) return Lib_Notice::response(4001);
        $request_data['ExtenType'] = 'gateway';
        if(is_numeric($request_data['Exten'])){
            return $this->model->Prequest('v20160818/call/dialout',$request_data);
        }else{
            return $this->model->Prequest('http://146.56.197.251:9565/api/call/dialout',$data);

        }
    }
    //转接
    public function transfer($data){
        if(!Lib_Notice::checkData($data,['FromExten','Exten','Mode'])) return Lib_Notice::response(4001);
        return $this->model->Prequest('v20160818/call/'.__FUNCTION__,$data);
    }
    //挂机
    public function hangup($data){
        $request_data['Agent'] = empty($data['workerId']) ? '' : $data['workerId'];
        if(!Lib_Notice::checkData($request_data,['Agent'])) return Lib_Notice::response(4001);
        return $this->model->Prequest('v20160818/call/hangup',$request_data);
    }
    //签入
    public function setIdle($data){
        $request_data['exten'] = empty($data['workerId']) ? '' : $data['workerId'];
        if(!Lib_Notice::checkData($request_data,['exten'])) return Lib_Notice::response(4001);
        $request_data['sign']='SignIn';
        $request_data['ExtenType']='gateway';
        return $this->model->Prequest('v20160818/account/SignInOrOut',$request_data);
    }
    //签出
    public function setBuys($data){
        $request_data['exten'] = empty($data['workerId']) ? '' : $data['workerId'];
        if(!Lib_Notice::checkData($request_data,['exten'])) return Lib_Notice::response(4001);
        $request_data['sign']='SignOut';
        return $this->model->Prequest('v20160818/account/SignInOrOut',$request_data);
    }
    //获取坐席
    public function getCCAgentsByAcc($data=[]){
        return $this->model->Prequest('v20160818/account/'.__FUNCTION__,$data);
    }
    //获取坐席状态
    public function queryUserState($data){
        $request_data['exten'] = empty($data['workerId']) ? '' : $data['workerId'];
        if(!Lib_Notice::checkData($request_data,['exten'])) return Lib_Notice::response(4001);
        return $this->model->Prequest('v20160818/user/'.__FUNCTION__,$request_data);
    }
    //获取技能组
    public function queryQueue($line){
        if($line == 1){
            return $this->model->Prequest('v20160818/queue/'.__FUNCTION__,['password'=>'1657OIUx']);
        }else{

        }
    }
    //获取技能组
    public function updateUser($data){
        if(!Lib_Notice::checkData($data,['exten'])) return Lib_Notice::response(4001);
        return $this->model->Prequest('v20160818/user/'.__FUNCTION__,$data);
    }
}
